package wiki.xsx.core.snowflake.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import wiki.xsx.core.snowflake.config.Snowflake;

/**
 * 雪花 API
 * @author xsx
 * @date 2019/11/20
 * @since 1.8
 */
@RestController
@RequestMapping("/snowflake")
public class SnowflakeApi {

    @Autowired
    private Snowflake snowflake;

    @GetMapping("/long")
    public Long getLong() {
        return this.snowflake.nextId();
    }

    @GetMapping("/string")
    public String getString() {
        return this.snowflake.nextIdStr();
    }

    @PostMapping("/used")
    public String getUsed() {
        return String.format("%s-%s", this.snowflake.getWorkerId(), this.snowflake.getDataCenterId());
    }
}
